-- This script demonstrates the CASE expression.
-- © Erland Sommarskog 2020.

DECLARE @n int = 1,
        @m int = 1,
        @b int,
        @f float = sqrt(2)

SELECT CASE WHEN @n = 1 THEN 5.12E24
            WHEN @m = 1 THEN PI()
            WHEN @n = 2 AND @m > 2 THEN @f + 1
            WHEN @n % 2 = 0 THEN (SELECT COUNT(*) FROM dbo.Customers)
            WHEN EXISTS (SELECT * FROM dbo.Customers WHERE City = 'Mokpo')
                         THEN CASE WHEN @b = 1      THEN dbo.MyDemoFunc(60)
                                   WHEN @b * @f > 5 THEN NULL
                                   ELSE -1
                              END
       END AS CaseDemo


